#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <iostream>
#define MP make_pair
using namespace std;

inline void read (int& s) {
	s = 0;
	static char c = getchar ();
	while (c < '0' || c > '9') c = getchar ();
	while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + (c ^ 48), c = getchar ();
	return ;
}

const int N = 503, M = 1003;
int n, sx, zx, m, h[N], tot;
struct stu {
	int v, next;
	int w, tag;
}s[M << 2];

inline void add (const int x, const int y, const int z, const int f) {
	++tot;
	s[tot].v = y;
	s[tot].next = h[x];
	s[tot].w = z;
	s[tot].tag = f;
	h[x] = tot;
	return ;
}

int d[N][2], ans[N], v, vis[N][2];
pair <int, int> pre[N][2], t;

struct QAQ {
	int pos, al, val;
	inline bool operator < (const QAQ& p) const {return val > p.val;}
}p;
priority_queue <QAQ> q;

int main () {
	int QwQ = 0;
	while (~scanf ("%d %d %d", &n, &sx, &zx)) {
		if (QwQ++) putchar ('\n');
		int i, x, y, z;
		memset (h, 0, sizeof (h));
		memset (pre, 0, sizeof (pre));
		tot = v = 0;
		read (m); while (m--) {
			read (x), read (y), read (z);
			add (x, y, z, 0);
			add (y, x, z, 0);
		}//tag为0表示非商业票
		read (m); while (m--) {
			read (x), read (y), read (z);
			add (x, y, z, 1);
			add (y, x, z, 1);
		}
		memset (d, 0x3f, sizeof (d));
		memset (vis, 0, sizeof (vis));
		d[sx][0] = 0;
		q.push ((QAQ) {sx, 0, 0});
		while (!q.empty ()){ 
			p = q.top ();
			q.pop ();
			x = p.pos;
			if (vis[x][p.al]) continue;
			vis[x][p.al] = 1;
			for (i = h[x]; i; i = s[i].next) {
				y = s[i].v;
				if (s[i].tag && p.al) continue; //已经用过就不能再用了
				z = d[x][p.al] + s[i].w;
				int t = p.al + s[i].tag; //已经用过或这次用后，都表示用过了
				if (d[y][t] > z) {
					d[y][t] = z;
					q.push ((QAQ) {y, t, d[y][t]});
					pre[y][t] = MP (x, p.al);
				}
			}
		}
		if (d[zx][0] < d[zx][1]) {
			x = zx, z = 0;
			while (x) {
				ans[++v] = x;
				t = pre[x][z];
				x = t.first, y = t.second;
			}
			printf ("%d", ans[v]);
			for (i = v - 1; i; --i) printf (" %d", ans[i]);
			puts ("\nTicket Not Used");
			printf ("%d\n", d[zx][0]);
		}
		else {
			x = zx, z = 1, y = 0;
			while (x) {
				ans[++v] = x;
				t = pre[x][z];
				x = t.first, z = t.second;
				if (!z && !y) y = x;
			}
			printf ("%d", ans[v]);
			for (i = v - 1; i; --i) printf (" %d", ans[i]);
			printf ("\n%d\n", y);
			printf ("%d\n", d[zx][1]);
		}
	}
	return 0;
}
